$(document).ready(function () {

    //点击返回
    $(".go-back").click(function () {
        var url = $(this).attr("url");
        console.log(url);
        window.location = url;
    });

    var clipboard = new ClipboardJS('.btn-share-link');
    clipboard.on('success', function (e) {
        console.log("复制成功!");
        layer.msg("复制成功");
        e.clearSelection();
    });

    clipboard.on('error', function (e) {
        console.log("复制失败");
        layer.msg("复制失败");
    });


    $(".share-popup").click(function () {
        $(this).hide();
    });

    $(".btn-save-pic").click(function () {


        let post = document.getElementById('middle-wrap')
        let width = post.offsetWidth
        let height = post.offsetHeight

        html2canvas(post, {
            backgroundColor: 'rgba(255, 255, 255, 0)',
            useCORS: true,
            allowTaint: false,
            width,
            height,
            logging: false,
            ignoreElements: (element) => {
                if (element.id === 'to_left') {
                    return true;
                }
                if (element.id === 'to_right') {
                    return true;
                }
            }
        }).then(canvas => {
            let share_pic = document.getElementById('share_pic');
            share_pic.src = canvas.toDataURL("image/png");
            $(".share-popup").show();
        });
    })

});

